<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>增加管理员用户</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <style>
        .layui-form {
            padding: 20px;
        }

    </style>
</head>

<body>
    <form class="layui-form" action="">
        @csrf
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="pwd" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选择角色</label>
            <div class="layui-input-block">
                <select name="role_title" lay-verify="required">
                {{-- <option value=""></option> --}}
                    @foreach ($groups as $group)
                        <option value="{{$group['gid']}}">{{$group['title']}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="uname" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                    class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label">状态</label>
            <input type="checkbox" name="status" title="禁用" >
        </div>

        <div class="layui-form-item">
            <button type="button" class="layui-btn layui-btn-sm btn-submit">提交</button>
        </div>
    </form>
</body>
<script src="/layui/jquery.js"></script>
<script src="/layui/layui.js"></script>
<script>

layui.use(['form'],function(){
    var form=layui.form;
    var $=layui.jquery;
})

// $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});



document.querySelector(".btn-submit").onclick=function(){
    var gid = parseInt($('select[name="role_title"]').val());
    var data={
        username:$.trim($("input[name='username']").val()),
        password:$.trim($("input[name='pwd']").val()),
        uname:$.trim($("input[name='uname']").val()),
        gid:gid
    }


    $.post("/admins/admin/save",$("form").serialize(),function (res) {
        console.log(res);
    },'json')
};




</script>

</html>
